package net.togogo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class FirstController {

    @RequestMapping(value = "first",method = RequestMethod.GET )
    public String FirstTest(){
        System.out.println("你好啊！这是第一个mvc测试例子");
        return "success";
    }

    //参数传递 浏览器传递参数被后台接收
    @RequestMapping(value = "say",method = RequestMethod.GET)
    public String sayName(String name){
        System.out.println("name = " + name);
        return "success";
    }

    //参数判断
    @RequestMapping(value = "age",method = RequestMethod.GET)
    public String sayAge(int age){
        if (age!=18){
            return "no18";
        }
        return "18";
    }

    //传递多个参数 @RequestParam 参数绑定 将指定名称的参数给控制器的形参赋值
    @RequestMapping(value = "login" ,method = RequestMethod.GET)
    public String login(@RequestParam("name") String username, @RequestParam("password") String userpassword){
        System.out.println("name = " + username);
        System.out.println("password = " + userpassword);
        return "success";
    }
}
